package com.smile.service.entity.device.property;

import com.alibaba.fastjson2.annotation.JSONField;

public class DroneStatusResponseData {

    @JSONField(name = "distance_limit_status")
    private DistanceLimitStatus distanceLimitStatus;

    // 嵌套类定义
    public static class DistanceLimitStatus {
        @JSONField(name = "state")
        private OperationState state;

        // Getter & Setter
        public OperationState getState() { return state; }
        public void setState(OperationState state) { this.state = state; }

        @Override
        public String toString() {
            return "DistanceLimitStatus{" +
                    "state=" + state +
                    '}';
        }
    }

    public static class OperationState {
        @JSONField(name = "result")
        private int result;  // 0:成功, 1:失败, 2:超时, 其他:错误原因码

        // Getter & Setter
        public int getResult() { return result; }
        public void setResult(int result) { this.result = result; }

        // 实用方法 - 判断操作是否成功
        public boolean isSuccess() {
            return result == 0;
        }

        // 实用方法 - 获取操作状态描述
        public String getResultDescription() {
            switch (result) {
                case 0: return "成功";
                case 1: return "失败";
                case 2: return "超时";
                default: return "错误码: 0x" + Integer.toHexString(result).toUpperCase();
            }
        }

        @Override
        public String toString() {
            return "OperationState{" +
                    "result=" + result + " (" + getResultDescription() + ")" +
                    '}';
        }
    }

    // Getter & Setter
    public DistanceLimitStatus getDistanceLimitStatus() {
        return distanceLimitStatus;
    }

    public void setDistanceLimitStatus(DistanceLimitStatus distanceLimitStatus) {
        this.distanceLimitStatus = distanceLimitStatus;
    }

    @Override
    public String toString() {
        return "DroneStatusResponseData{" +
                "distanceLimitStatus=" + distanceLimitStatus +
                '}';
    }

    // 实用方法 - 快速访问状态结果
    public int getOperationResult() {
        return distanceLimitStatus != null && distanceLimitStatus.getState() != null
                ? distanceLimitStatus.getState().getResult()
                : -1;  // 返回-1表示状态不可用
    }
}
